<%@ page import="com.stu.entity.permission.User" %>
<%@ page import="com.stu.utils.CommonUtils" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<jsp:include page="common.jsp"></jsp:include> 
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<% 
	String path = request.getContextPath(); 
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<style>
<!--
#py-ul li:hover{
	background-color: #ddd;
	color:white;
	font-family:'Microsoft Yahei', sans-serif;
}
-->
</style>

<div class="navbar-wrapper navbar_top">
		<div class="container">
			<nav class="navbar navbar-default ">
				<div class="container-fluid">
					<div class="navbar-header">
						<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
							<span class="sr-only">Toggle navigation</span> 
							<span class="icon-bar"></span> 
							<span class="icon-bar"></span> 
							<span class="icon-bar"></span>  
						</button>
						<a class="navbar-brand" id="py-brand" href="#"><span></span>GEEK_HOME</a>
					</div> 

					<div class="collapse navbar-collapse"
						id="bs-example-navbar-collapse-1">  
						<ul class="nav navbar-nav" id="py-ul">
							<li class="couldActive"><a href="<%=basePath%>pages/index.jsp">首页 <span class="sr-only">(current)</span></a></li>
							<li class="couldActive"><a href="<%=basePath %>pages/blog_list.jsp">博客</a></li>
							<li class="couldActive"><a href="<%=basePath %>pages/news_list.jsp">新闻</a></li>
							<%-- <li><a href="<%=basePath %>about">我的动态</a></li> --%>
							<%-- <li class="couldActive"><a href="<%=basePath %>pages/about.html">关于我们</a></li> --%>
							<li class="couldActive"><a href="<%=basePath %>pages/aboutUs.jsp">关于我们</a></li>
							
							<c:choose>
								<c:when test="${ !empty currentUser}">     
									<li class="dropdown">
									<a href="#" class="dropdown-toggle" data-toggle="dropdown">动态 <b class="caret"></b></a>
										<ul class="dropdown-menu">
											<li><a href="<%=basePath %>pages/my_blog_list.jsp">博客管理</a></li>
											
											
											<%-- 如果是超级管理员 还拥有下面的权限 --%>
											<c:if test="${ currentUser.uuid == 'admin'}">
												<li class="divider"></li>
												<!-- <li class="nav-header">灰掉</li> --> 
												<li><a href="http://127.0.0.1:8080/geek/monitoring" target="_blank">项目监控</a></li>
												<li><a href="http://127.0.0.1:8080/geek/pages/admin_news_list.jsp" target="_blank">新闻管理</a></li>
												<li><a href="<%=basePath %>pages/log_list.jsp">日志管理</a></li>
												<li><a href="<%=basePath %>pages/cache_manger.jsp">缓存管理</a></li>
											</c:if>
										</ul>
									</li> 
					         </c:when>  
					         </c:choose>
							
							

						</ul>
						<div>
						
							<c:choose>
								<c:when test="${empty currentUser}">     
								<p class="navbar-text navbar-right">
									<a href="<%=basePath %>login.jsp">登录 </a>| <a href="<%=basePath %>register.html">注册</a>
								</p>
					         </c:when>  
					         <c:otherwise>  
					            <ul class="nav navbar-nav navbar-right">
									<li class="dropdown">
									<a href="#" class="dropdown-toggle" 
										data-toggle="dropdown">${currentUser.nickname }<b class="caret"></b></a>
										<ul class="dropdown-menu"> 
											<li><a href="<%=basePath %>/pages/user_info.jsp">个人信息</a></li> 
											<li><a href="<%=basePath %>/pages/updatepasswd.jsp">修改密码</a></li> 
											<li class="divider"></li> 
											<li><a href="javascript:void(0);" onclick="logout()">退出登录</a></li>
										</ul></li>
								</ul>  
					         </c:otherwise> 
							</c:choose>
							
							
							
						</div>
					</div>
				</div> 
		</nav>
	</div>
	</div>
	<%-- 天气和时间 start --%> 
	<div style="width:80%;margin-left:auto;margin-right:auto;margin-bottom:3px;">
		<span id="nowTime1" style="float:left;"></span> 
		<span id="nowTime" class="visible-lg" style="float:right;margin-bottom:3px;"></span>
	</div>
	<%-- 天气和时间 end --%>
	
	
	
	<script type="text/javascript">
	
	
	
	var path='<%=basePath%>';
	
		$(function(){
			console.log('${ empty currentUser}'=='true');
			if('${ empty currentUser}'=='true'){
				window.location.href='<%=basePath%>'+"/login.jsp";
				/* console.log('${ empty currentUser}'); */
			}
			
			initWeather();
			beginAutoRefreshNowTimeLabel();
		})
		new CookieUtils().setCookie("duoshuo_token", "${duoshuoToken}");
		/* alert(new CookieUtils().getCookie("duoshuo_token")); */
		/**
		 * 刷新屏幕当前时间显示
		 */
		function beginAutoRefreshNowTimeLabel() {
			var refresh = function() {
				$('#nowTime').text($.date.toLongDateTimeString(new Date()));
			};
			refresh();
			window.setInterval(refresh, 1000);
		};
		function logout(){
			
			try{
				new CookieUtils().delCookie("duoshuo_token");
				console.log(new CookieUtils().getCookie("duoshuo_token")); 
			}catch(e){}
			$.ajax({ 
				type:"POST",   
				url:path+"/user_doNotNeedSession_logoutJson.action",
				dataType:"json",
				success:function(result){
					console.log(result);
					window.location.href='<%=basePath%>'+"/login.jsp";
				}
			});
		}
		/**
		 * 初始化天气数据
		 * cityid 查询 
		 * http://wenku.baidu.com/link?url=a3d43Z1cVplXDpKr4fxO6TNVa8Fa7qQY8eVBiUTI8ytbVvpud5Au5CkNqIZV-9_b-pOYl1W6k3VKcHAqqaH-5xtmcagC9Biq_GPM6pC_0sG
		 * 
		 */
		function initWeather() {
			var path="/geek/user_getRedisV.action?rediskey=cityid";
			$.ajax({
				type : "GET",
				url : path,
				dataType : 'json',
				success : function(result) {
					var cityid=result.redisvalue;
					if(cityid==""||cityid=="null"||cityid==null||cityid==undefined){
						cityid=101120501;//默认烟台
					}					
					var weapath="http://apis.baidu.com/apistore/weatherservice/recentweathers?cityid="+cityid;
					
					$.ajax({
						type : "GET",
						url : weapath,
						beforeSend : function(request) {
							request.setRequestHeader("apikey",
									"3e0130d4cd21e1976732a43f3b4259f7");
						},
						dataType : 'json',
						success : function(result) {
							/*console.log(result);
						 console.log("city:"+result.retData.city);
						console.log("hightemp:"+result.retData.today.hightemp);
						console.log("lowtemp:"+result.retData.today.lowtemp);
						console.log("curTemp:"+result.retData.today.curTemp);
						console.log("fengli:"+result.retData.today.fengli);
						console.log("type:"+result.retData.today.type); */
							$('#nowTime1').text(result.retData.city+" "+result.retData.today.type+" "+result.retData.today.fengli+" "+result.retData.today.lowtemp+"~"+result.retData.today.hightemp);
						},
						error:function(){
							$('#nowTime1').text("网络在开小差~~没有查询到天气数据");
						}
					});
				}
			});
			
		}
		 
		/* $(".couldActive").each(function(){
			this.click(function(){
				changeActive(this);
			})
		}) */
		
		/* $(".couldActive").bind("click",function(e){
			  
			
	        e = e || window.event;
	        var tar = e.srcElement || e.target;
			console.log("click..."+this);
	            this.addClass("active");
	            return false; 
    	})  */
		
		/* 改变 导航 active  */
		function changeActive(e){
			$(".navbar-nav li").removeClass("active");
			this.addClass("active");
			
		}
		
	</script>
	
	